package com.example.demo.controller;

import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController

public class HelloController {
    @RequestMapping("/hello")
    public String hello() {
        return "Hello SpringBoot:"+ nameAges.toString();
    }

    private static HashMap<String, Integer> nameAges = new HashMap<>();

    @PostMapping("/hello")
    public String helloPost(String name, int age) {
        nameAges.put(name, age);
        return "add name:"+name +" age:"+age;
    }

    @PutMapping("/hello")
    public String helloPut(String name, int age) {
        nameAges.replace(name, age);
        return "updata name:"+name +" ,age:"+age;
    }

    @DeleteMapping("/hello/{name}")
    public String helloDel(@PathVariable String name) {
        nameAges.remove(name);
        return "del name:"+name;
    }

}
